package com.vcaresolution.logistic.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.vcaresolution.logistic.pojo.Branch;

/**
 * The <code>CompanyDAO</code> class is a DAO Associated to do various 
 * options at DAO level for Company
 *
 * @author Sneahl Shah
 * @version 1.0
 * @since ShipSoft 1.0
 */
@Repository
public class CompanyDAO extends BaseDAO{

	@SuppressWarnings("unchecked")
	@Transactional
	public List<Branch> getAssociatedBranchList(Serializable companyId){
		
		/**#editedByVishal*/
		Integer companyIdInteger = null;
		if(companyId instanceof String)
		{
			companyIdInteger = Integer.parseInt((String) companyId);
		}
		else
		{
			companyIdInteger = (Integer)companyId;
		}
		
		List<Branch> branchList = sessionFactory
										.getCurrentSession()
										.createCriteria(Branch.class,"branch")
										.createAlias("branch.company", "company")
										.setFetchMode("company", FetchMode.JOIN)
										.add(Restrictions.eq("company.companyid", companyIdInteger))
										.createAlias("branch.city", "city")
										.setFetchMode("city", FetchMode.JOIN)
										.list();
		
		return branchList;
	}
	
}
